<?php
namespace app\api\controller;
use app\model\MotifModel;
use think\facade\Request;

class backstage{
    //后台
    public function backstage_list(){
        session_start();
        $name = $_SESSION['admin_name'];
        $motif = MotifModel::select();
        $motifarr = [[]];
        foreach($motif as $key =>$value ){
            $motifarr[$key][] = $value['motif_name'];
            $motifarr[$key][] = $value['motif_id'];
            $motifarr[$key][] = date("Y-m-d H:i:s",$value['add_time']);
            if($value['update_time']==0){
                $motifarr[$key][] = $value['update_time'];
            }else{
                $motifarr[$key][] = date("Y-m-d H:i:s",$value['update_time']);
            }

        }
//        var_dump($motifarr);
        $data = [
            'status' => 0,
            'message' => '',
            'data' => [$name,$motifarr]
        ];
        return json($data);
    }
    public function delete(){
        $motifid = Request::param('motifid');
        $motif = MotifModel::find($motifid);
        $motif['motif_state'] = 2;
        $result = $motif->save();
        if($result){
            $data = [
                'status' => 0,
                'message' => '删除成功',
                'data' => $motifid
            ];
            return json($data);
        }else{
            $data = [
                'status' => 10001,
                'message' => '删除失败',
                'data' => $motifid
            ];
            return json($data);
        }
    }
}